package com.atguigu.cloud.exp;

import com.atguigu.cloud.resp.ResultCodeEnum;
import com.atguigu.cloud.resp.ResultData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * ClassName:    GlobalExceptionHandler
 * Package:  com.atguigu.cloud.exp
 * Description:
 *
 * @Author: interface
 * @Create: 2025/7/16 - 上午6:16
 * @Version: v1.0
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(value = RuntimeException.class) //处理的异常为 RuntimeException
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) // 回应状态
    public ResultData<String> exceptionHandler(Exception e){
        log.error("全局异常信息:{}", e.getMessage(),e);
        return ResultData.error(ResultCodeEnum.RC500.getCode(),ResultCodeEnum.RC500.getMessage());
    }
}
